
capture log close
clear *
log using appendix-log.log, replace

***************************************************************
* Klasnja, Lupu, Tucker: 
* "When Do Voters Sanction Corrupt Politicians?"
* This do file replicates the results show in the appendix. 
***************************************************************

* for further details, see the readme.txt file in the replication archive
* user-written command -coefplot- needed; type 'ssc install coefplot'
* user-written command -frmttable- needed; type 'ssc install frmttable'
* user-written command -estout- needed; type 'ssc install estout'
* user-written plot scheme -plotplain- needed; type 'net install gr0070'

*** Table A1: Summary statistics
use analysis-data, clear
mat n = J(1,4,.)
mat sum = J(9,4,.)
bys uniq_id: egen count = seq(), from(1)
keep if count == 1
qui sum uniq_id
mat n1 = r(N)
tab country, matcell(n2)
mat n2 = n2'
mat n = n1,n2
gen corperchi1 = (corperc > 3) if corperc ~= .
preserve
collapse r_female r_age loed2 lowealth unemp bribejust corperchi1 corperchi anybribe [pw=weight1500]
mkmat r_female-anybribe, mat(s1)
mat s1 = s1'
restore
collapse r_female r_age loed2 lowealth unemp bribejust corperchi1 corperchi anybribe [pw=weight1500], by(country)
mkmat r_female-anybribe, mat(s2)
mat s2 = s2'
mat sum = s1,s2
mat all = sum \ n
frmttable, statmat(all) substat(0) sdec(2 \ 2 \ 2 \ 2 \ 2 \ 2 \ 2 \ 2 \ 2 \ 0) ///
	rtitles("Female" \ "Age" \ "Less than high school" \ "Wealth (in bottom 3 quintiles)" \ ///
		"Unemployment" \ "Bribes justifiable" \ "High corruption perception" \ ///
		"Very high corruption perception" \ ///
		"Bribe paid" \ "Observations") ///
	ctitles("","All","Argentina","Chile","Uruguay")
frmttable, clear


*** Figure A1: Diagnostic check for profile order effects
use analysis-data, clear
* incumbent
reg vote i.corrupttreat badeconomy i.copartisan i.copsource2 i.female i.country if arias == 0 [pw=weight1500], cl(uniq_id)
estimates store r1
* challenger
reg vote i.corrupttreat badeconomy i.copartisan i.copsource2 i.female i.country if arias == 1 [pw=weight1500], cl(uniq_id)
estimates store r2
coefplot (r1, label(Incumbent) msymbol(T) msize(medsmall) mcolor(black%80) offset(0.2)) ///
	(r2, label(Challenger) msymbol(S) msize(medsmall) mcolor(gray%80) offset(-0.2)), ///
	scheme(plotplain) xline(0, lcolor(black) lpattern(solid) lwidth(vthin)) baselevels ///
	graphregion(color(white)) drop(_cons 1.country 2.country 3.country) legend(ring(0) position(1)) ///
		xtitle("Effect on Pr(Voting for candidate)") coeflabels(, labsize(small)) grid(glcolor(gs2)) ///
		headings(1.corrupttreat = "{bf:Corruption}" ///
			0.badeconomy = "{bf:Economy}" ///
			0.female = "{bf: Gender}" ///
			0.copartisan = "{bf:Partisanship}" ///
			0.copsource2 = "{bf:Information source}")


*** Table A2: Results with economy and gender interactions
eststo clear
use analysis-data, clear
eststo: reg vote i.corrupttreat i.copartisan i.badeconomy##inc i.copsource2 i.female i.country ///
	[pw=weight1500], cl(uniq_id)
eststo: reg vote (i.corrupttreat i.copartisan inc i.copsource2 i.female i.country)##i.badeconomy ///
	[pw=weight1500], cl(uniq_id)
eststo: reg vote (i.corrupttreat i.copartisan i.badeconomy##inc i.copsource2 i.country)##i.female ///
	[pw=weight1500], cl(uniq_id)
esttab, label b(2) se(2) nonumbers nobaselevels nolegend star(* 0.10 ** 0.05 *** 0.01) ///
	mtitles("Main model" "Interactions w/ economy" "Interactions w/ female") drop(2.country 3.country) ///
	wide
	

*** Table A3: Randomization checks
eststo clear
use analysis-data, clear
eststo: reg r_female i.corrupttreat i.copartisan i.badeconomy##i.inc i.copsource2 i.female i.country [pw=weight1500], cl(uniq_id)
eststo: reg r_age i.corrupttreat i.copartisan i.badeconomy##i.inc i.copsource2 i.female i.country [pw=weight1500], cl(uniq_id)
eststo: reg ed i.corrupttreat i.copartisan i.badeconomy##i.inc i.copsource2 i.female i.country [pw=weight1500], cl(uniq_id)
esttab, label b(2) se(2) nonumbers nobaselevels nolegend star(* 0.10 ** 0.05 *** 0.01) ///
	mtitles("Gender" "Age" "Education") drop(2.country 3.country _cons)
	
	
*** Table A4: Coefficient Estimates for Figures 1-3 in the main text
eststo clear
use analysis-data, clear
eststo: reg vote i.corrupttreat i.copartisan i.badeconomy##i.inc i.copsource2 i.female i.country [pw=weight1500], cl(uniq_id)
eststo: reg vote i.corrupttreat##i.copartisan i.badeconomy##i.inc i.copsource2 i.female i.country [pw=weight1500], cl(uniq_id)
eststo: reg vote i.corrupttreat##i.bribejust i.copartisan i.badeconomy##i.inc i.copsource2 i.female i.country [pw=weight1500], cl(uniq_id)
eststo: reg vote i.corrupttreat##i.loed2 i.copartisan i.badeconomy##i.inc i.copsource2 i.female i.country [pw=weight1500], cl(uniq_id)
eststo: reg vote i.corrupttreat##i.lowealth i.copartisan i.badeconomy##inc i.copsource2 i.female i.country [pw=weight1500], cl(uniq_id)
esttab, label b(2) se(2) nonumbers nobaselevels nolegend star(* 0.10 ** 0.05 *** 0.01) ///
	mlabels("Figure 1" "Figure 2" "Figure 2" "Figure 3" "Figure 3")


*** Table A5: Estimates with OLS and Logit
eststo clear
use analysis-data, clear
eststo ols: reg vote i.corrupttreat i.copartisan i.badeconomy##i.inc i.copsource2 ///
	i.female i.country [pw=weight1500], cl(uniq_id)
logit vote i.corrupttreat i.copartisan i.badeconomy##i.inc i.copsource2 ///
	i.female i.country [pw=weight1500], cl(uniq_id)
eststo mfx: margins, dydx(*) post
logit vote i.corrupttreat i.copartisan i.badeconomy##i.inc i.copsource2 ///
	i.female i.country [pw=weight1500], cl(uniq_id)
margins, dydx(badeconomy) at(inc = (0 1))
margins, dydx(inc) at(badeconomy = 0)
* (manually fix the economy effects in column 2)
esttab ols mfx, label b(3) se(2) nonumbers nobaselevels nolegend star(* 0.10 ** 0.05 *** 0.01) ///
	mtitles("OLS" "Logit") drop(_cons)

	
*** Table A6: Multiple-Comparison Correction for Main Estimates
use analysis-data, clear
reg vote i.corrupttreat i.copartisan i.badeconomy##i.inc i.copsource2 i.female i.country [pw=weight1500], cl(uniq_id)
mat coef = e(b)
mat pval = r(table)
local C = colsof(pval)
mat pval = pval[4..4,1..`C']
mat coef = coef', pval'
scalar R = rowsof(coef)-1
mat coef = coef[1..R,1..2]
clear
svmat double coef
gen names = ""
local names : rownames coef
local k = 1
foreach i of local names {
replace names = "`i'" in `k'
local k = `k' + 1
}
egen base = rowtotal(coef*)
drop if base == 0
drop base
rename coef2 pval
gen orig_order = _n
sort pval
gen pval_order = _n if pval ~= .
sum pval_order
local max = r(max)
gen bh1 = (pval_order/`max')*0.05
gen bh2 = (pval < bh1)
gen orig = (pval < .05)
gen fail = (orig ~= bh2)
sort orig_order
drop in 11/12
mkmat coef1 pval orig bh1 bh2, mat(ests)
frmttable, statmat(ests) substat(0) sdec(3,3,0,3,0) ///
	rtitles("Bribes" \ "Bribes common" \ "Bribes but jobs" \ ///
	"Co-partisan candidate" \ "Worsened economy" \ "Incumbent profile" \ "Worsened economy $\times$ incumbent" \ ///
	"Out-partisan source" \ "Co-partisan source" \ "Female") ///
	ctitles("","Point","Original","Sig. at","B-H \$ p$-value","Sig. at" \ ///
	"","Estimate","$ p$-value","$ p<.05$","threshold","B-H $ p<.05$")
frmttable, clear

	
*** Figure A2: Treatment Effects, by Country
cap estimates store clear
use analysis-data, clear
reg vote i.corrupttreat badeconomy##arias i.copartisan i.copsource2 i.female if country == 1 [pw=weight1500], cl(uniq_id)
estimates store arg
reg vote i.corrupttreat badeconomy##arias i.copartisan i.copsource2 i.female if country == 2 [pw=weight1500], cl(uniq_id)
estimates store chi
reg vote i.corrupttreat badeconomy##arias i.copartisan i.copsource2 i.female if country == 3 [pw=weight1500], cl(uniq_id)
estimates store uru
coefplot (arg, label(Argentina) msymbol(O) msize(vsmall) offset(0.27)) ///
	(chi, label(Chile) msymbol(T) msize(vsmall) offset(0)) ///
	(uru, label(Uruguay) msymbol(S) msize(vsmall) offset(-0.27)), ///
	scheme(plotplain) xline(0, lcolor(black) lpattern(solid) lwidth(vthin)) baselevels ///
	graphregion(color(white)) drop(_cons 0.arias 0.badeconomy#0.arias 0.badeconomy#1.arias 1.badeconomy#0.arias ///
		1.arias 1.badeconomy#1.arias) legend(ring(0) position(1)) ///
		xtitle("Effect on Pr(Voting for candidate)") coeflabels(, labsize(small)) grid(glcolor(gs2)) ///
		headings(1.corrupttreat = "{bf:Corruption}" ///
			0.badeconomy = "{bf:Economy} (incumbent only)" ///
			0.female = "{bf: Gender}" ///
			0.copartisan = "{bf:Partisanship}" ///
			0.copsource2 = "{bf:Information source}")


*** Table A7: Corruption Treatment Effects, by Country
use analysis-data, clear
forval i = 2/4 {
	mat b`i' = J(1,6,.)
	mat bp`i' = J(1,6,.)
	mat d`i' = J(1,6,.)
	mat dp`i' = J(1,6,.)
	}
forval a = 2/4 {
	* effects
	qui reg vote i.corrupttreat##i.country badeconomy##arias i.copartisan i.copsource2 i.female [pw=weight1500], cl(uniq_id)
	margins, dydx(`a'.corrupttreat) at(country = (1 2 3)) post
	mat tab = r(table)
	local j 1 3 5
	local k 2 4 6
	forval i = 4/6 {
		local m = `i'-3
		local n : word `m' of `j'
		local p : word `m' of `k'
		mat b`a'[1,`n'] = tab[1,`i']
		mat b`a'[1,`p'] = tab[2,`i']
		mat bp`a'[1,`n'] = tab[4,`i']
		}
	* differences across countries
	qui reg vote i.corrupttreat##i.country badeconomy##arias i.copartisan i.copsource2 i.female [pw=weight1500], cl(uniq_id)
	margins, dydx(`a'.corrupttreat) at(country = (1 2 3)) post
	* Argentina vs. Chile
	lincom _b[`a'.corrupttreat:1._at]-_b[`a'.corrupttreat:2._at]
	mat d`a'[1,1] = r(estimate)
	mat d`a'[1,2] = r(se)
	mat dp`a'[1,1] = r(p)
	* Argentina vs. Uruguay
	lincom _b[`a'.corrupttreat:1._at]-_b[`a'.corrupttreat:3._at]
	mat d`a'[1,3] = r(estimate)
	mat d`a'[1,4] = r(se)
	mat dp`a'[1,3] = r(p)
	* Chile vs. Uruguay
	lincom _b[`a'.corrupttreat:2._at]-_b[`a'.corrupttreat:3._at]
	mat d`a'[1,5] = r(estimate)
	mat d`a'[1,6] = r(se)
	mat dp`a'[1,5] = r(p)
	}
* differences across treatments within country
qui reg vote i.corrupttreat##i.country badeconomy##arias i.copartisan i.copsource2 i.female [pw=weight1500], cl(uniq_id)
margins, dydx(corrupttreat) at(country = (1 2 3)) post
forval i = 1/2 {
	mat db`i' = J(1,6,.)
	mat dbp`i' = J(1,6,.)
	mat dd`i' = J(1,6,.)
	mat ddp`i' = J(1,6,.)
	}
local j 1 3 5
local k 2 4 6
forval i = 1/3 {
	local n : word `i' of `j'
	local p : word `i' of `k'
	* bribes common vs. bribes
	lincom _b[3.corrupttreat:`i'._at]-_b[2.corrupttreat:`i'._at]
	mat db1[1,`n'] = r(estimate)
	mat db1[1,`p'] = r(se)
	mat dbp1[1,`n'] = r(p)
	* bribes but jobs vs. bribes
	lincom _b[4.corrupttreat:`i'._at]-_b[2.corrupttreat:`i'._at]
	mat db2[1,`n'] = r(estimate)
	mat db2[1,`p'] = r(se)
	mat dbp2[1,`n'] = r(p)
	}
* differences in differences: across treatments and countries
* bribes common vs. bribes
local j 1 3 5
local k 2 4 6
local x 1 1 2
local y 2 3 3
forval i = 1/3 {
	local n : word `i' of `j'
	local p : word `i' of `k'
	local x1 : word `i' of `x'
	local y1 : word `i' of `y'
	* bribes common vs. bribes
	lincom _b[3.corrupttreat:`x1'._at]-_b[2.corrupttreat:`x1'._at]-(_b[3.corrupttreat:`y1'._at]-_b[2.corrupttreat:`y1'._at])
	mat dd1[1,`n'] = r(estimate)
	mat dd1[1,`p'] = r(se)
	mat ddp1[1,`n'] = r(p)
	* bribes but jobs vs. bribes
	lincom _b[4.corrupttreat:`x1'._at]-_b[2.corrupttreat:`x1'._at]-(_b[4.corrupttreat:`y1'._at]-_b[2.corrupttreat:`y1'._at])
	mat dd2[1,`n'] = r(estimate)
	mat dd2[1,`p'] = r(se)
	mat ddp2[1,`n'] = r(p)
	}
* putting all results together into a table
mat t = J(1,12,.)
mat top1 = b2 \ b3 \ b4 
mat top2 = d2 \ d3 \ d4
mat top = top1, top2
mat top = t \ top
mat b = J(1,12,.)
mat bot1 = db1 \ db2
mat bot2 = dd1 \ dd2 
mat bot = bot1, bot2
mat bot = b \ bot
mat all = top \ bot
mat ptop1 = bp2 \ bp3 \ bp4
mat ptop2 = dp2 \ dp3 \ dp4
mat ptop = ptop1, ptop2
mat ptop = t \ ptop
mat pbot1 = dbp1 \ dbp2
mat pbot2 = ddp1 \ ddp2
mat pbot = pbot1, pbot2
mat pbot = b \ pbot
mat pval = ptop \ pbot
mat stars = J(8,12,0)
local cols = colsof(pval)
local rows = rowsof(pval)
forval i = 1/`rows' {
	forval j = 1/`cols' {
		local pval = pval[`i',`j']
		if `pval' <= .10 & `pval' > .05 {
			matrix stars[`i',`j'] = 1
			}
		if `pval' <= .05 & `pval' > .01 {
			matrix stars[`i',`j'] = 2 
			}
		if `pval' <= .01 {
			matrix stars[`i',`j'] = 3
		}
	}
}
frmttable, statmat(all) substat(1) sdec(2) annotate(stars) asymbol(*,**,***) ///
	statfont(fs11) hlines(1001{0}1) vlines(00001{0}) ///
	rtitles("\textbf{Corruption treatments}" \ "" \ "\hspace{1em} Bribes" \ "" \ ///
			"\hspace{1em} Bribes common" \ "" \ "\hspace{1em} Bribes but jobs" \ "" \ ///
			"\textbf{Diff. in corruption treatments}" \ "" \ ///
			"\hspace{1em} Bribes common vs. bribes" \ "" \ ///
			"\hspace{1em} Bribes but jobs vs. bribes" \ "") ///
	ctitles("","By country","","","Diff. across countries","","" \ ///
			"","Argentina","Chile","Uruguay","Argentina","Argentina","Chile" \ ///
			"","","","","vs. Chile","vs. Uruguay","vs. Uruguay") ///
	multicol(1,2,3;1,5,3) noblankrows
	
	
*** Figures A3 and A4
* define program that collects results
cap prog drop bycorr
prog def bycorr
	args m /* m = moderator */
	use analysis-data, clear
	mat ests = J(10,3,.)
	mat diffs = J(3,1,.)
	reg vote i.corrupttreat##i.`m' badeconomy##arias i.copartisan i.copsource2 i.female i.country ///
		[pw=weight1500], cl(uniq_id)
	margins, dydx(corrupttreat) at(`m' = (0 1)) post
	mat tab = r(table)
	local j 2 3 5 6 8 9
	local k 3 4 5 6 7 8
	forval i = 1/6 {
		loc m : word `i' of `j'
		loc n : word `i' of `k'
		mat ests[`m',1] = tab[1,`n']
		mat ests[`m',2] = tab[5,`n']
		mat ests[`m',3] = tab[6,`n']
		}
	forval i = 1/3 {
		loc a = `i'+1
		lincom _b[`a'.corrupttreat:2._at]-_b[`a'.corrupttreat:1._at]
		mat diffs[`i',1] = r(estimate)
		}
end

*** Figure A3: Corruption Treatment Effects, by Respondents’ Corruption Perception
bycorr corperchi
clear
svmat ests
gen n = .
for any 1.1 1.5 2 3.1 3.5 4 5.1 5.5 6 6.2 \ any 1 2 3 4 5 6 7 8 9 10: replace n = X in Y
svmat diffs
gen n2 = .
for any 1.75 3.75 5.75 \ any 1 2 3: replace n2 = X in Y
tostring diffs1, gen(diffs_) force format(%9.3f)
gen stars = "" in 1
replace stars = "" in 2
replace stars = "*" in 3
egen diffs = concat(diffs_ stars)
gen t = "Diff.: " in 1/3
egen lab = concat(t diffs)
forval i = 1/3 {
	loc l`i' = lab in `i'
	di "`l`i''"
	}
twoway (rcap ests2 ests3 n, msize(0) lcol(black) horizontal) ///
		(scatter n ests1, mcol(black) msize(medium) msymbol(O)), ///
		legend(off) scheme(plotplain) ///
		ylabel(1.1 "{bf:Bribes}" 1.5 "Low corr. perception" 2 "High corr. perception" ///
				3.1 "{bf:Bribes common}" 3.5 "Low corr. perception" ///
				4 "High corr. perception" 5.1 "{bf:Bribes but jobs}" ///
				5.5 "Low corr. perception" 6 "High corr. perception", ///
				labgap(6pt) noticks nogrid angle(0) labsize(small)) ytitle("") ///
		xscale(range(-0.45(.1).05)) xlabel(#6, glcolor(gs2)) xtitle("Effect on Pr(Voting for candidate)") ///
		yscale(reverse )  ytick(1.5 2 3.5 4 5.5 6, grid glcolor(gs2)) ///
		xline(0, lcolor(black) lpattern(dash) lwidth(vthin))  ///
		text(1.71 -.24 "`=ustrunescape("\u23AB")'" "`=ustrunescape("\u23AC")'" "`=ustrunescape("\u23AD")'" , size(small) color(black)) ///
		text(1.75 -.19 "`l1'", size(small)) ///
		text(3.71 -.23 "`=ustrunescape("\u23AB")'" "`=ustrunescape("\u23AC")'" "`=ustrunescape("\u23AD")'" , size(small) color(black)) ///
		text(3.75 -.18 "`l2'", size(small)) ///
		text(5.73 -.13 "`=ustrunescape("\u23AB")'" "`=ustrunescape("\u23AC")'" "`=ustrunescape("\u23AD")'" , size(small) color(black)) ///
		text(5.75 -.08 "`l3'", size(small)) 


*** Figure A4: Corruption Treatment Effects, by Respondents’ Bribe Experience
bycorr anybribe
clear
svmat ests
gen n = .
for any 1.1 1.5 2 3.1 3.5 4 5.1 5.5 6 6.2 \ any 1 2 3 4 5 6 7 8 9 10: replace n = X in Y
svmat diffs
gen n2 = .
for any 1.75 3.75 5.75 \ any 1 2 3: replace n2 = X in Y
tostring diffs1, gen(diffs_) force format(%9.3f)
gen stars = "" in 1
replace stars = "" in 2
replace stars = "*" in 3
egen diffs = concat(diffs_ stars)
gen t = "Diff.: " in 1/3
egen lab = concat(t diffs)
forval i = 1/3 {
	loc l`i' = lab in `i'
	di "`l`i''"
	}
twoway (rcap ests2 ests3 n, msize(0) lcol(black) horizontal) ///
		(scatter n ests1, mcol(black) msize(medium) msymbol(O)), ///
		legend(off) scheme(plotplain) ///
		ylabel(1.1 "{bf:Bribes}" 1.5 "Not paid bribe" 2 "Paid bribe" ///
				3.1 "{bf:Bribes common}" 3.5 "Not paid bribe" ///
				4 "Paid bribe" 5.1 "{bf:Bribes but jobs}" ///
				5.5 "Not paid bribe" 6 "Paid bribe", ///
				labgap(6pt) noticks nogrid angle(0) labsize(small)) ytitle("") ///
		xscale(range(-0.45(.1).05)) xlabel(#6, glcolor(gs2)) xtitle("Effect on Pr(Voting for candidate)") ///
		yscale(reverse )  ytick(1.5 2 3.5 4 5.5 6, grid glcolor(gs2)) ///
		xline(0, lcolor(black) lpattern(dash) lwidth(vthin))  ///
		text(1.71 -.18 "`=ustrunescape("\u23AB")'" "`=ustrunescape("\u23AC")'" "`=ustrunescape("\u23AD")'" , size(small) color(black)) ///
		text(1.75 -.13 "`l1'", size(small)) ///
		text(3.71 -.25 "`=ustrunescape("\u23AB")'" "`=ustrunescape("\u23AC")'" "`=ustrunescape("\u23AD")'" , size(small) color(black)) ///
		text(3.75 -.20 "`l2'", size(small)) ///
		text(5.73 -.08 "`=ustrunescape("\u23AB")'" "`=ustrunescape("\u23AC")'" "`=ustrunescape("\u23AD")'" , size(small) color(black)) ///
		text(5.75 -.03 "`l3'", size(small)) 


*** Figure A5: Corruption Treatment Effects, by Information Source
use analysis-data, clear
reg vote i.corrupttreat##i.copsource2 badeconomy##arias i.copartisan i.female i.country ///
	[pw=weight1500], cl(uniq_id)
margins, dydx(corrupttreat) at(copsource2 = (0 1 2)) post
mat tab = r(table)
mat ests = J(13,3,.)
local j 2 3 4 6 7 8 10 11 12
local k 4 5 6 7 8 9 10 11 12
forval i = 1/9 {
	loc m : word `i' of `j'
	loc n : word `i' of `k'
	mat ests[`m',1] = tab[1,`n']
	mat ests[`m',2] = tab[5,`n']
	mat ests[`m',3] = tab[6,`n']
	}
clear
svmat ests
gen n = .
for any 1.1 1.5 2 2.5 3.6 4 4.5 5 6.1 6.5 7 7.5 7.7 \ any 1 2 3 4 5 6 7 8 9 10 11 12 13: replace n = X in Y
twoway (rcap ests2 ests3 n, msize(0) lcol(black) horizontal) ///
		(scatter n ests1, mcol(black) msize(medium) msymbol(O)), ///
		legend(off) scheme(plotplain) ///
		ylabel(1.1 "{bf:Bribes}" 1.5 "Judicial officials" 2 "Out-partisan newspaper" ///
				2.5 "Co-partisan newspaper" 3.6 "{bf:Bribes common}" 4 "Judicial officials" ///
				4.5 "Out-partisan newspaper" 5 "Co-partisan newspaper" 6.1 "{bf:Bribes but jobs}" ///
				6.5 "Judicial officials" 7 "Out-partisan newspaper" 7.5 "Co-partisan newspaper", ///
				labgap(6pt) noticks nogrid angle(0) labsize(small)) ytitle("") ///
		xscale(range(-0.5(.1)-0.1)) xlabel(#6, glcolor(gs2)) xtitle("Effect on Pr(Voting for candidate)") ///
		yscale(reverse )  ytick(1.5 2 2.5 4 4.5 5 6.5 7 7.5, grid glcolor(gs2)) 


*** Figure A6: What Conditions Amplify the Mitigating Effect of Side Benefits?
use analysis-data, clear
mat ests = J(13,3,.)
mat diffs = J(6,1,.)
* state of the economy
reg vote i.corrupttreat##badeconomy##inc i.copartisan i.copsource2 i.female i.country [pw=weight1500], cl(uniq_id)
margins, dydx(2.corrupttreat 4.corrupttreat) at(inc = 1 badeconomy = (0 1)) post
mat tab = r(table)
local j = 3
foreach i in 2 3 5 6 {
	mat ests[`i',1] = tab[1,`j']
	mat ests[`i',2] = tab[5,`j']
	mat ests[`i',3] = tab[6,`j']
	local j = `j' + 1
	}
lincom _b[2.corrupttreat:2._at]-_b[2.corrupttreat:1._at]
mat diffs[1,1] = r(estimate)
lincom _b[4.corrupttreat:2._at]-_b[4.corrupttreat:1._at]
mat diffs[2,1] = r(estimate)
lincom _b[4.corrupttreat:2._at]-_b[4.corrupttreat:1._at]-(_b[2.corrupttreat:2._at]-_b[2.corrupttreat:1._at])
mat diffs[3,1] = r(estimate)
* employment status
reg vote i.corrupttreat##i.unemp badeconomy##arias i.copartisan i.copsource2 i.female i.country [pw=weight1500], cl(uniq_id)
margins, dydx(2.corrupttreat 4.corrupttreat) at(unemp = (0 1)) post
mat tab = r(table)
local j = 3
foreach i in 8 9 11 12 {
	mat ests[`i',1] = tab[1,`j']
	mat ests[`i',2] = tab[5,`j']
	mat ests[`i',3] = tab[6,`j']
	local j = `j' + 1
	}
lincom _b[2.corrupttreat:2._at]-_b[2.corrupttreat:1._at]
mat diffs[4,1] = r(estimate)
lincom _b[4.corrupttreat:2._at]-_b[4.corrupttreat:1._at]
mat diffs[5,1] = r(estimate)
lincom _b[4.corrupttreat:2._at]-_b[4.corrupttreat:1._at]-(_b[2.corrupttreat:2._at]-_b[2.corrupttreat:1._at])
mat diffs[6,1] = r(estimate)
* creating the graph
clear
svmat ests
gen n = .
for any 1.1 1.5 2 3.1 3.5 4 5.6 6 6.5 7.6 8 8.5 8.7 \ any 1 2 3 4 5 6 7 8 9 10 11 12 13: replace n = X in Y
svmat diffs
gen n2 = .
for any 1.75 3.75 2.75 6.25 8.25 7.25 \ any 1 2 3 4 5 6: replace n2 = X in Y
tostring diffs1, gen(diffs_) force format(%9.3f)
gen stars = "" in 1/6
egen diffs = concat(diffs_ stars)
gen t = "Diff.: " in 1/6
egen lab = concat(t diffs)
forval i = 1/6 {
	loc l`i' = lab in `i'
	di "`l`i''"
	}
twoway (rcap ests2 ests3 n, msize(0) lcol(black) horizontal) ///
		(scatter n ests1, mcol(black) msize(medium) msymbol(O)), ///
		legend(off) scheme(plotplain) ///
		ylabel(1.1 "{bf: Improving economy}" 1.5 "Bribes" 2 "Bribes but jobs" ///
				3.1 "{bf: Worsening economy}" 3.5 "Bribes" 4 "Bribes but jobs" ///
				5.6 "{bf: Employed}" 6 "Bribes" 6.5 "Bribes but jobs" ///
				7.6 "{bf: Unemployed}" 8 "Bribes" 8.5 "Bribes but jobs", ///
				labgap(5pt) noticks nogrid angle(0) labsize(small)) ytitle("") ///
		xscale(range(-0.6(.1).1)) xlabel(#6, glcolor(gs2)) xtitle("Effect on Pr(Voting for candidate)") ///
		yscale(reverse )  ytick(1.5 2 3.5 4 6 6.5 8 8.5, grid glcolor(gs2)) ///
		xline(0, lcolor(black) lpattern(dash) lwidth(vthin)) ///
		text(1.73 -.27 "`=ustrunescape("\u23AB")'" "`=ustrunescape("\u23AC")'" "`=ustrunescape("\u23AD")'" , size(vsmall) color(black)) ///
		text(1.75 -.20 "`l1'", size(small)) ///
		text(3.73 -.17 "`=ustrunescape("\u23AB")'" "`=ustrunescape("\u23AC")'" "`=ustrunescape("\u23AD")'" , size(vsmall) color(black)) ///
		text(3.75 -.10 "`l2'", size(small)) ///
		text(2.63 .025 "`=ustrunescape("\u23AB")'" "`=ustrunescape("\u23AC")'" "`=ustrunescape("\u23AD")'" , size(huge) color(black)) ///
		text(2.79 .12 "`l3'", size(medium)) ///
		text(6.23 -.255 "`=ustrunescape("\u23AB")'" "`=ustrunescape("\u23AC")'" "`=ustrunescape("\u23AD")'" , size(vsmall) color(black)) ///
		text(6.25 -.185 "`l4'", size(small)) ///
		text(8.23 -.125 "`=ustrunescape("\u23AB")'" "`=ustrunescape("\u23AC")'" "`=ustrunescape("\u23AD")'" , size(vsmall) color(black)) ///
		text(8.25 -.055 "`l5'", size(small)) ///
		text(7.13 .025 "`=ustrunescape("\u23AB")'" "`=ustrunescape("\u23AC")'" "`=ustrunescape("\u23AD")'" , size(huge) color(black)) ///
		text(7.25 .12 "`l6'", size(medium)) ///
		yline(5, lpattern(solid) lcolor(gray) lwidth(vthin))


*** Figure A7: Economy Treatment Effect, by Country and Respondents’ Retrospective Economic Perceptions
use analysis-data, clear
mat ests = J(19,3,.)
* overall, pooled
reg vote i.corrupttreat badeconomy##arias i.copartisan i.copsource2 i.female i.country ///
	[pw=weight1500], cl(uniq_id)
margins, dydx(badeconomy) at(arias == 0) post
mat tab = r(table)
mat ests[2,1] = tab[1,2]
mat ests[2,2] = tab[5,2]
mat ests[2,3] = tab[6,2]
* overall, by country
reg vote i.corrupttreat badeconomy##arias##i.country i.copartisan i.copsource2 i.female ///
	[pw=weight1500], cl(uniq_id)
margins, dydx(badeconomy) at(arias == 0 country = (1 2 3)) post
mat tab = r(table)
forval i = 3/5 {
	loc j = `i'+1
	mat ests[`i',1] = tab[1,`j']
	mat ests[`i',2] = tab[5,`j']
	mat ests[`i',3] = tab[6,`j']
	}
* by economic perceptions, pooled
reg vote i.corrupttreat badeconomy##arias##i.econperc i.copartisan i.copsource2 i.female i.country ///
	[pw=weight1500], cl(uniq_id)
margins, dydx(badeconomy) at(arias == 0 econperc = (0 1)) post
mat tab = r(table)
forval i = 8/9 {
	loc j = `i'-5
	mat ests[`i',1] = tab[1,`j']
	mat ests[`i',2] = tab[5,`j']
	mat ests[`i',3] = tab[6,`j']
	}
* by economic perceptions, by country
reg vote i.corrupttreat i.country##badeconomy##arias##i.econperc i.copartisan i.copsource2 i.female ///
	[pw=weight1500], cl(uniq_id)
margins, dydx(badeconomy) at(arias == 0 econperc = (0 1) country = (1 2 3)) post
mat tab = r(table)
forval i = 11/12 {
	loc j = `i'-4
	mat ests[`i',1] = tab[1,`j']
	mat ests[`i',2] = tab[5,`j']
	mat ests[`i',3] = tab[6,`j']
	}
forval i = 14/15 {
	loc j = `i'-5
	mat ests[`i',1] = tab[1,`j']
	mat ests[`i',2] = tab[5,`j']
	mat ests[`i',3] = tab[6,`j']
	}
forval i = 17/18 {
	loc j = `i'-6
	mat ests[`i',1] = tab[1,`j']
	mat ests[`i',2] = tab[5,`j']
	mat ests[`i',3] = tab[6,`j']
	}
clear
svmat ests
gen n = _n
replace n = n+1 if n > 5
twoway (rcap ests2 ests3 n, msize(0) lcol(black) horizontal) ///
		(scatter n ests1, mcol(black) msize(medium) msymbol(O)), ///
		legend(off) scheme(plotplain) ///
		ylabel(1 "{bf:Overall}" 2 "Pooled" 3 "Argentina" ///
			4 "Chile" 5 "Uruguay" 7 "{bf:By economic perceptions}" ///
			8 "{bf:Pooled}" 9 "Economy not worse" 10 "Economy worse" ///
			11 "{bf:Argentina}" 12 "Economy not worse" 13 "Economy worse" ///
			14 "{bf:Chile}" 15 "Economy not worse" 16 "Economy worse" ///
			17 "{bf:Uruguay}" 18 "Economy not worse" 19 "Economy worse", ///
				labgap(6pt) noticks nogrid angle(0) labsize(small)) ytitle("") ///
		xscale(range(-0.2(.05).05)) xlabel(#6, glcolor(gs2)) xtitle("Effect on Pr(Voting for candidate)") ///
		yscale(reverse )  ytick(2 3 4 5 9 10 12 13 15 16 18 19, grid glcolor(gs2)) ///
		xline(0, lcolor(black) lpattern(solid) lwidth(vthin)) ///
		yline(6.5, lpattern(solid) lcolor(gray) lwidth(vthin))


*** Figure A8: Conventional Analysis vs. ANOVA-based Approach by Egami and Imai (2019)
* prep data for R to run the estimation
* notes: analysis without weights; estimation doesn't converge with economy and country dummies included
use analysis-data, clear
keep uniq_id vote corrupttreat copartisan copsource female 
recode corrupttreat (4 = 1) (3 = 2) (2 = 3) (1 = 4), gen(bribe)
recode copartisan (0 = 1) (1 = 0)
lab def bribe 4 "NoBribes" 3 "Bribes" 2 "BribesCommon" 1 "BribesJobs", replace
lab val bribe bribe
lab def copartisan 1 "OutCand" 0 "CopCand", replace
lab val copartisan copartisan
lab def copsource 0 "Court" 1 "OutNews" 2 "CopNews", replace
lab val copsource copsource
lab def female 0 "Male" 1 "Female", replace
lab val female female
drop if vote == .
rename uniq id
drop corruptt
order id vote bribe copartisan copsource female
saveold temp-R, replace v(12)

* now run 'FigureA8.R', which exports a csv file 'ei.csv' to be used for graphing

reg vote b1.copartisan##b4.bribe b1.copsource b1.female, cl(id)
margins, dydx(bribe) at(copartisan = (0 1)) post
mat tab = r(table)
mat ests = J(9,3,.)
local j 1 3 5
forval i = 1/3 {
	loc m : word `i' of `j'
	loc p = `i' + 1
	mat ests[`p',1] = tab[1,`m']
	mat ests[`p',2] = tab[5,`m']
	mat ests[`p',3] = tab[6,`m']
	}
local j 2 4 6
forval i = 1/3 {
	loc m : word `i' of `j'
	loc p = `i' + 5
	mat ests[`p',1] = tab[1,`m']
	mat ests[`p',2] = tab[5,`m']
	mat ests[`p',3] = tab[6,`m']
	}
clear
* import file created by the R script
import delimited ei.csv, varnames(1) clear
rename conditionaleffectscopartisancopc ests1_c1
rename v4 ests2_c1
rename v5 ests3_c1
rename conditionaleffectscopartisanoutc ests1_c0
rename v8 ests2_c0
rename v9 ests3_c0
keep ests*
drop in 4
mkmat ests1_c1-ests3_c1, mat(c1)
mkmat ests1_c0-ests3_c0, mat(c0)
mat c = J(1,3,.)
mat ests_ei = c \ c1 \ c \ c0 \ c
clear
svmat ests
svmat ests_ei
gen n = .
for any 1 4 3 2 6 9 8 7 10 \ any 1 2 3 4 5 6 7 8 9: replace n = X in Y
twoway (rcap ests2 ests3 n, msize(0) lcol(black) horizontal) ///
		(scatter n ests1, mcol(black) msize(medium) msymbol(O)), ///
		legend(off) scheme(plotplain) ///
		ylabel(1 "{bf:Co-partisan candidate}" 2 "Bribes" 3 "Bribes common" ///
			4 "Bribes but jobs" 6 "{bf:Out-partisan candidate}" ///
			7 "Bribes" 8 "Bribes common" 9 "Bribes but jobs", ///
			labgap(6pt) noticks nogrid angle(0) labsize(small)) ytitle("") ///
		xscale(range(-0.6(.2)0)) xlabel(#4, glcolor(gs2)) xtitle("Effect on Pr(Voting for candidate)") ///
		yscale(reverse )  ytick(2 3 4 7 8 9, grid glcolor(gs2)) title(Conventional) ///
		xline(0, lcolor(black) lpattern(dash) lwidth(vthin)) name(g1, replace)
twoway (rcap ests_ei2 ests_ei3 n, msize(0) lcol(gray) horizontal) ///
		(scatter n ests_ei1, mcol(gray) msize(medium) msymbol(T)), ///
		legend(off) scheme(plotplain) ///
		ylabel(1 "{bf:Co-partisan candidate}" 2 "Bribes" 3 "Bribes common" ///
			4 "Bribes but jobs" 6 "{bf:Out-partisan candidate}" ///
			7 "Bribes" 8 "Bribes common" 9 "Bribes but jobs", ///
			labgap(6pt) noticks nogrid angle(0) labsize(small)) ytitle("") ///
		xscale(range(-0.6(.2)0)) xlabel(#4, glcolor(gs2)) xtitle("Effect on Pr(Voting for candidate)") ///
		yscale(reverse alt)  ytick(2 3 4 7 8 9, grid glcolor(gs2)) title(ANOVA-based) ///
		xline(0, lcolor(black) lpattern(dash) lwidth(vthin)) name(g2, replace)
gr combine g1 g2, xcommon ycommon scheme(plotplain) rows(1)


*** Figure A9: Candidate Partisanship and Co-Partisan Bias Effects for Alternative Respondent Partisanship Measures
use analysis-data, clear
* candidate co-partisanship
* party ID
mat ests = J(10,3,.)
reg vote i.corrupttreat badeconomy##arias i.copartisan i.copsource2 i.female i.country [pw=weight1500], ///
	cl(uniq_id)
lincom 1.copartisan
mat ests[3,1] = r(estimate)
mat ests[3,2] = r(lb)
mat ests[3,3] = r(ub)
* left-right
reg vote i.corrupttreat badeconomy##arias i.copartisan2 i.copsource2 i.female i.country [pw=weight1500], ///
	cl(uniq_id)
mat tab = r(table)
lincom 1.copartisan2
mat ests[4,1] = r(estimate)
mat ests[4,2] = r(lb)
mat ests[4,3] = r(ub)
* co-partisan bias
reg vote i.corrupttreat##i.copartisan badeconomy##arias i.copsource2 i.female i.country [pw=weight1500], ///
	cl(uniq_id)
margins, dydx(2.corrupttreat) at(copartisan = (0 1)) post
mat tab = r(table)
forval i = 3/4 {
	local j = `i'*2
	mat ests[`j',1] = tab[1,`i']
	mat ests[`j',2] = tab[5,`i']
	mat ests[`j',3] = tab[6,`i']
	}
reg vote i.corrupttreat##i.copartisan2 badeconomy##arias i.copsource2 i.female i.country [pw=weight1500], ///
	cl(uniq_id)
margins, dydx(2.corrupttreat) at(copartisan = (0 1)) post
mat tab = r(table)
forval i = 3/4 {
	local j = `i'*2+1
	mat ests[`j',1] = tab[1,`i']
	mat ests[`j',2] = tab[5,`i']
	mat ests[`j',3] = tab[6,`i']
	}
clear
svmat ests	
forval i = 1/3 {
	replace ests`i' = 0 in 2
	}
gen alt = 0
foreach x in 4 7 9 {
	replace alt = 1 in `x'
	}
gen n = .
for any 1.1 1.3 1.5 1.7 2.1 2.3 2.5 2.7 2.9 3.1 \ any 1 2 3 4 5 6 7 8 9 10: replace n = X in Y
gen base = 0
replace base = 1 in 2
twoway (rcap ests2 ests3 n if alt == 0, msize(0) lcol(black) horizontal) ///
		(scatter n ests1 if alt == 0, mcol(black) msize(medium) msymbol(T)) ///
		(rcap ests2 ests3 n if alt == 1, msize(0) lcol(gray) horizontal) ///
		(scatter n ests1 if alt == 1, mcol(gray) msize(medium) msymbol(S)) ///
		(scatter n ests1 if base == 1, mcol(black) msize(medlarge) msymbol(O)), ///
		legend(ring(0) pos(5) order(2 "Party ID" 4 "Left-right")) scheme(plotplain) ///
		ylabel(1.1 "{bf: Candidate partisandship}" 1.3 "Out-partisan candidate ({it:reference})" ///
				1.6 "Co-partisan candidate" ///
				2.1 "{bf: Co-partisan bias}" 2.4 "Bribes & out-partisan candidate" ///
				2.8 "Bribes & co-partisan candidate", ///
				labgap(6pt) noticks nogrid angle(0) labsize(small)) ytitle("") ///
		xscale(range(-0.6(.1)0)) xlabel(#4, glcolor(gs2)) xtitle("Effect on Pr(Voting for candidate)") ///
		yscale(reverse )  ytick(1.3 1.5 1.7 2.3 2.5 2.7 2.9, grid glcolor(gs2) notick) ///
		xline(0, lcolor(black) lpattern(dash) lwidth(vthin))
		

*** Figure A10: Left-Party vs. Right-Party Candidate Effects
use analysis-data, clear
gen lr = 0
replace lr = 1 if leftid==1 & party==1
replace lr = 2 if rightid== 1 & party==2
mat ests = J(9,3,.)
* candidate partisanship
reg vote i.corrupttreat badeconomy##arias i.lr i.copsource2 i.female i.country [pw=weight1500], ///
	cl(uniq_id)
margins, dydx(lr) post
mat tab = r(table)
forval i = 2/3 {
	local j = `i'+1
	mat ests[`j',1] = tab[1,`i']
	mat ests[`j',2] = tab[5,`i']
	mat ests[`j',3] = tab[6,`i']
	}
* co-partisan bias
reg vote i.corrupttreat##i.lr badeconomy##arias i.copsource2 i.female i.country [pw=weight1500], ///
	cl(uniq_id)
margins, dydx(2.corrupttreat) at(lr = (0 1 2)) post
mat tab = r(table)
forval i = 4/6 {
	local j = `i' + 2
	mat ests[`j',1] = tab[1,`i']
	mat ests[`j',2] = tab[5,`i']
	mat ests[`j',3] = tab[6,`i']
	}
clear
svmat ests	
forval i = 1/3 {
	replace ests`i' = 0 in 2
	}
gen alt = 0
foreach x in 4 8 {
	replace alt = 1 in `x'
	}
foreach x in 2 6 {
	replace alt = 2 in `x'
	}
gen n = .
for any 1.1 1.3 1.5 1.7 2.1 2.3 2.5 2.7 2.9 \ any 1 2 3 4 5 6 7 8 9: replace n = X in Y
twoway (rcap ests2 ests3 n if alt == 0, msize(0) lcol(black) horizontal) ///
		(scatter n ests1 if alt == 0, mcol(black) msize(medium) msymbol(T)) ///
		(rcap ests2 ests3 n if alt == 1, msize(0) lcol(black) horizontal) ///
		(scatter n ests1 if alt == 1, mcol(black) msize(medium) msymbol(S)) ///
		(rcap ests2 ests3 n if alt == 2, msize(0) lcol(gray) horizontal) ///
		(scatter n ests1 if alt == 2, mcol(gray) msize(medium) msymbol(O)), ///
		legend(ring(0) pos(5) order(2 "Left party" 4 "Right party" 6 "Independent")) scheme(plotplain) ///
		ylabel(1.1 "{bf: Candidate partisandship}" 1.3 "Independent ({it:reference})" ///
				1.5 "Left party co-partisan" 1.7 "Right party co-partisan" ///
				2.1 "{bf: Co-partisan bias}" 2.3 "Bribes & independent candidate" ///
				2.5 "Bribes & left party co-partisan candidate" ///
				2.7 "Bribes & right party co-partisan candidate", ///
				labgap(6pt) noticks nogrid angle(0) labsize(small)) ytitle("") ///
		xscale(range(-0.6(.1)0)) xlabel(#4, glcolor(gs2)) xtitle("Effect on Pr(Voting for candidate)") ///
		yscale(reverse )  ytick(1.3 1.5 1.7 2.3 2.5 2.7, grid glcolor(gs2)) ///
		xline(0, lcolor(black) lpattern(dash) lwidth(vthin))

gr drop _all

log close

** end of do-file